/// LoadModel
// argument0: fileName
// argument1: model ID

var curr_pos = 0;
var curr_nor = 0;
var curr_uv = 0;

// Load raw data from file
var file = file_text_open_read(argument0);

num_verts = file_text_read_real(file);
for (var i = 0; i < num_verts; i++)
{
    pos[argument1, curr_pos] = file_text_read_real(file);
    curr_pos++;
    pos[argument1, curr_pos] = file_text_read_real(file);
    curr_pos++;
    pos[argument1, curr_pos] = file_text_read_real(file);
    curr_pos++;
    nor[argument1, curr_nor] = file_text_read_real(file);
    curr_nor++;
    nor[argument1, curr_nor] = file_text_read_real(file);
    curr_nor++;
    nor[argument1, curr_nor] = file_text_read_real(file);
    curr_nor++;
    uv[argument1, curr_uv] = file_text_read_real(file);
    curr_uv++;
    uv[argument1, curr_uv] = file_text_read_real(file);
    curr_uv++;
}

num_indices = file_text_read_real(file);
for (var i = 0; i < num_indices; i++)
{
    indices[argument1, i] = file_text_read_real(file);
}

file_text_close(file);

for (var i = 0; i < num_indices; i += 3)
{
    // Change winding order
    var temp = indices[argument1, i];
    indices[argument1, i] = indices[argument1, i + 2];
    indices[argument1, i + 2] = temp;
}

for (var i = 0; i < num_indices; i++)
{
    var index = indices[argument1, i];
            
    verts[curr_uni_vert] = pos[argument1, index * 3];
    curr_uni_vert++;
    verts[curr_uni_vert] = pos[argument1, index * 3 + 1];
    curr_uni_vert++;
    verts[curr_uni_vert] = pos[argument1, index * 3 + 2];
    curr_uni_vert++;
}

/**
// Create model from data
var model = d3d_model_create();
d3d_model_primitive_begin(model, pr_trianglelist);

for (var i = 0; i < num_indices; i++)
{
    var index = indices[i];
    d3d_model_vertex_texture(model,
        pos[index * 3], pos[index * 3 + 1], pos[index * 3 + 2],
        //nor[index * 3], nor[index * 3 + 1], nor[index * 3 + 2],
        uv[index * 2 + 1], 1 - uv[index * 2]);
}

d3d_model_primitive_end(model);
return model;
/**/
